package com.sky.zzh.util;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.sky.zzh.R;
import com.sky.zzh.SHApplication;
import com.sky.zzh.SHContainerActivity;
import com.sky.zzh.sleepset.SleepSetFragment;

public class AlarmReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent arg1) {
		// TODO Auto-generated method stub
//		Toast.makeText(context, "闹钟时间到", Toast.LENGTH_SHORT).show();
//		System.out.println("ttttttttttt");
		Intent it = new Intent(context,SHContainerActivity.class);
		it.putExtra("class", SleepSetFragment.class.getName());
		sendNotification("智照护", "智照护", "睡眠时间到了", it, 0);
		
		
	}
	
	private void sendNotification(String ticktitle, String title, String message, Intent intent, int notificationId) {

		int icon = R.drawable.ic_login_logo; // 为通知定义一个图标

		String Ticktitle = ticktitle; // 通知栏信息

		String content = message; // 通知内容

		// 定义一个通知对象

		Notification notification = new Notification(icon, Ticktitle, System.currentTimeMillis());

		PendingIntent pi = PendingIntent.getActivity(SHApplication.getInstance(), notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);

		notification.setLatestEventInfo(SHApplication.getInstance(), title, content, pi);
		// notification.

		notification.defaults = Notification.DEFAULT_SOUND; // 设置通知声音【此处为系统默认】

		notification.flags = Notification.FLAG_AUTO_CANCEL;// 设置点击通知后通知栏中的通知消

		// 获取通知管理器

		NotificationManager manager = (NotificationManager) SHApplication.getInstance()
				.getSystemService(Context.NOTIFICATION_SERVICE);
		
//		String taskName = intent.getStringExtra("task_name");
//		String taskTime = intent.getStringExtra("task_time");
		
//		Log.i(TAG,"taskName = " + taskName + ", taskTime = " + taskTime);
		

		manager.notify(notificationId, notification); // 第一个参数为该通知的编号【唯一的标识即可】

	}

}
